package com.farm.proxy;

import com.farm.equipment.Equipment;
import com.farm.equipment.EquipmentState;

public class EquipmentProxy extends Equipment {
    private Equipment realEquipment;
    private String accessLevel;

    public EquipmentProxy(Equipment realEquipment, String accessLevel) {
        super(realEquipment.getId(), realEquipment.getName());
        this.realEquipment = realEquipment;
        this.accessLevel = accessLevel;
    }

    @Override
    public void work() {
        if (checkAccess()) {
            System.out.println("代理：允许访问设备");
            realEquipment.work();
        } else {
            System.out.println("代理：拒绝访问设备，权限不足");
        }
    }

    @Override
    public void stop() {
        if (checkAccess()) {
            System.out.println("代理：允许停止设备");
            realEquipment.stop();
        } else {
            System.out.println("代理：拒绝停止设备，权限不足");
        }
    }

    private boolean checkAccess() {
        // 模拟权限检查
        return "ADMIN".equals(accessLevel);
    }

    @Override
    public void setState(EquipmentState state) {
        if (checkAccess()) {
            realEquipment.setState(state);
        }
    }

    @Override
    public void setFuelLevel(double fuelLevel) {
        if (checkAccess()) {
            realEquipment.setFuelLevel(fuelLevel);
        }
    }

    @Override
    public void setLocation(String location) {
        if (checkAccess()) {
            realEquipment.setLocation(location);
        }
    }
}